package com.xebest.web.controller.finance;


import com.alibaba.fastjson.JSON;
import com.xebest.api.fin.dto.ManagerFinPayBillPageDto;
import com.xebest.api.fin.dto.XeSysFinPayBillRequestDTO;
import com.xebest.api.fin.service.XeSysFinPayBillRestApiService;
import com.xebest.common.base.controller.BASEMessage;
import com.xebest.common.base.controller.BaseController;
import com.xebest.common.base.controller.BaseResponse;
import com.xebest.util.DateUtil;
import com.xebest.util.SysSetBeanUtils;
import com.xebest.util.XeVenExcelUtil;
import com.xebest.util.XeVenImportExcelUtil;
import com.xebest.util.msg.XeVenAfterSaleMsg;
import com.xebest.web.controller.export.XeSysFinPayBillExport;
import com.xebest.web.controller.export.XeVenFinPurchPayExDTO;
import com.xebest.web.controller.export.XeVenFinSalesBillExDTO;
import com.xebest.web.controller.export.XeVenOrderRefundDTO;
import com.xebest.web.form.XeVenFinPurchPayForm;
import com.xebest.web.form.XeVenFinSalesBillForm;
import com.xebest.web.form.XeVenOrderRefundQueryForm;
import com.xebest.web.service.XeVenFinPurchPayCenterExportService;
import com.xebest.web.service.XeVenFinSalesBillService;
import com.xebest.web.service.XeVenOrderReFundService;
import com.xebest.web.view.ErpUserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

/**
 * 财务中心导出
 *
 * @author 赵盼飞
 */
@RestController
@RequestMapping("finance")
public class XeVenFinPurchPayCenterExportController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(XeVenFinPurchPayCenterExportController.class);// 日志记录类

    /**
     * 获取退款单相关
     */
    @Autowired
    XeVenOrderReFundService reFundService;
    /**
     * 处理财务中心导出数据
     */
    @Autowired
    private XeVenFinPurchPayCenterExportService finPurchPayCenterExportService;

    @Value("${xeven.erp.exportTempletDir}")
    private String exportTempletDir;// 导出文件目录

    /**
     * 收款单业务操作
     */
    @Autowired
    private XeVenFinSalesBillService xeVenFinSalesBillService;

    /**
     * 财务付款单二方包service
     */
    @Autowired
    private XeSysFinPayBillRestApiService xeSysFinPayBillRestApiService;

    /**
     * 导出付款单列表
     *
     * @author 赵盼飞
     */
    @RequestMapping("exFinPurchPayList")
    public @ResponseBody
    BaseResponse exportfinPurchPayList(@ModelAttribute XeVenFinPurchPayForm form,
                                       HttpServletResponse response) {
        try {
            String[] str = new String[]{"startSettleDate", "psettleCode", "supplierName", "purchId", "purchStatus",
                    "storeName", "psettleStatus", "rejectStatus", "frontMoney", "orderId", "orderStatus", "sendTime",
                    "sendStoreName", "receiptPurAmount", "proPayAmount", "settleDate", "settlementMethod", "settlementCycle",
                    "purchType", "accBank", "bankAccName", "bankAccCard"};
            form.setFieldArr(str);
            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            // 2.获取数据
            List<XeVenFinPurchPayExDTO> finPurchPayEList = finPurchPayCenterExportService
                    .queryExportfinPurchPayList(form);
            if (null != finPurchPayEList && finPurchPayEList.size() > 0) {
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(finPurchPayEList, new XeVenFinPurchPayExDTO(),
                        form.getFieldArr(), exportTempletDir, "FINPURCHPAYLIST-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("导出付款单列表接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 导出付款单明细
     *
     * @author 赵盼飞
     */
    @RequestMapping("exFinPurchPayDetail")
    public @ResponseBody
    BaseResponse exportfinPurchPayDetail(@ModelAttribute XeVenFinPurchPayForm form,
                                         HttpServletResponse response) {

        try {
            // 测试使用
            String[] str = new String[]{"startSettleDate", "psettleCode", "supplierName", "purchId", "purchStatus",
                    "storeName", "psettleStatus", "rejectStatus", "frontMoney", "orderId", "orderStatus", "sendTime",
                    "sendStoreName", "receiptAmountDetail", "proPayAmount", "settleDate", "settlementMethod", "settlementCycle",
                    "purchType", "proName", "specValue", "proNum", "pricingType", "proUnit", "purchNum", "buyPrice",
                    "purchPrice", "purInNum", "receiptStorePrice", "accBank", "bankAccName", "bankAccCard"};
            form.setFieldArr(str);

            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            // 2.获取数据
            List<XeVenFinPurchPayExDTO> finPurchPayEList = finPurchPayCenterExportService.exportfinPurchPayDetail(form);

            // 3.导出
            if (finPurchPayEList.size() > 0 && null != finPurchPayEList) {
                boolean rs = XeVenExcelUtil.exportExcelService(finPurchPayEList, new XeVenFinPurchPayExDTO(),
                        form.getFieldArr(), exportTempletDir, "FINPURCHPAYDETAIL-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("导出付款单明细接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 导出收款单列表
     *
     * @author 赵盼飞
     */
    @RequestMapping("exFinSalesBillList")
    public @ResponseBody
    BaseResponse exportfinSalesBillList(@ModelAttribute XeVenFinSalesBillForm form,
                                        HttpServletResponse response) {

        try {
            // 测试
            String[] str = new String[]{"months", "sbillCode", "sendTime", "orderId", "goodsAmount",
                    "payAmount", "sfAmount", "differAmount", "realSbillAmount", "sbillStatus", "receiveTime",
                    "sbillPayType", "payType", "orderRemark", "orderStatus", "caStreet", "area", "sbillRemark"};
            form.setFieldArr(str);
            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            // 2.获取数据
            List<XeVenFinSalesBillExDTO> finSalesBillEList = finPurchPayCenterExportService
                    .queryExportfinSalesBillList(form);
            if (null != finSalesBillEList && finSalesBillEList.size() > 0) {
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(finSalesBillEList, new XeVenFinSalesBillExDTO(),
                        form.getFieldArr(), exportTempletDir, "FINSALESBILLLIST-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("导出收款单列表接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 导出收款单明细
     *
     * @author 赵盼飞
     */
    @RequestMapping("exFinSalesBillDetail")
    public @ResponseBody
    BaseResponse exportfinSalesBillDetail(@ModelAttribute XeVenFinSalesBillForm form,
                                          HttpServletResponse response) {

        try {

            // 测试
            String[] str = new String[]{"sbillCode", "months", "sbillCode", "sendTime", "orderId", "goodsAmount",
                    "payAmount", "sfAmount", "differAmountDetail", "proPayAmount", "realSbillAmount", "sbillStatus", "receiveTime",
                    "sbillPayType", "payType", "orderRemark", "orderStatus", "caStreet", "area", "sbillRemark",
                    "proNum", "proName", "specValue", "proUnit", "pricingType", "proCostPrice", "purchaseNum",
                    "proPayAmountDetail", "realSendNum", "proPayAmount", "differNum", "differenceAmounts"};
            form.setFieldArr(str);

            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            // 2.获取数据
            List<XeVenFinSalesBillExDTO> finSalesBillEDetail = finPurchPayCenterExportService
                    .queryExportfinSalesBillDetail(form);
            if (null != finSalesBillEDetail && finSalesBillEDetail.size() > 0) {
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(finSalesBillEDetail, new XeVenFinSalesBillExDTO(),
                        form.getFieldArr(), exportTempletDir, "FINSALESBILLDETAIL-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }

        } catch (Exception e) {
            log.error("导出收款单明细接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 收款单列表导入
     *
     * @author 赵盼飞
     */
    @RequestMapping("impfinSalesBill")
    public @ResponseBody
    BaseResponse impfinSalesBill(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> rsInfoMap = new HashMap<String, Object>();// 返回提示信息map
        try {
            CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
                    request.getSession().getServletContext());
            if (commonsMultipartResolver.isMultipart(request)) { // 判断是否是上传
                List<MultipartFile> fileUploadss = ((MultipartHttpServletRequest) request).getFiles("xlsFiles");
                if (fileUploadss != null && fileUploadss.size() > 0) {
                    // excel文件一次导入一个
                    MultipartFile fileUpload = fileUploadss.get(0);
                    // 生成上传文件名称
                    String fileName = fileUpload.getOriginalFilename();
                    InputStream in = fileUpload.getInputStream();

                    // 读取导入的EXCEL信息
                    List<List<Object>> listInfo = XeVenImportExcelUtil.getBankListByExcel(in, fileName);
                    if (listInfo.size() >= 500) {
                        return sendAjaxError("最多导入500条！");
                    }
                    ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
                    XeVenFinSalesBillForm xsb = new XeVenFinSalesBillForm();
                    xsb.setUserCode(userInfo.getUserCode());
                    // 获取数据库表中信息
                    List<XeVenFinSalesBillExDTO> finSalesBillEDetail = finPurchPayCenterExportService
                            .queryExportfinSalesBillDetail(xsb);
                    Set<String> dbOrders = new HashSet<String>();// 数据库中存在的订单
                    for (XeVenFinSalesBillExDTO finSalesBill : finSalesBillEDetail) {
                        dbOrders.add(finSalesBill.getOrderId());
                    }
                    // 获取数据库表中信息
                    List<List<Object>> errorList = new ArrayList<List<Object>>();// 导入失败的数据
                    List<XeVenFinSalesBillForm> yesList = new ArrayList<XeVenFinSalesBillForm>();// 需要更新的数据
                    int orderIndexs = 0; // 订单编号对应的EXCEL列坐标
                    int payIndexs = 0; // 收款方式对应的EXCEL列坐标
                    int reTimeIndexs = 0; // 收款日期对应的EXCEL列坐标
                    int amountIndexs = 0; // 实收金额对应的EXCEL列坐标
                    int sRemarkIndexs = 0; // 收款单备注对应的EXCEL列坐标
                    boolean orderFlag = false;// 用于区分坐标不混淆
                    boolean payFlag = false;// 用于区分坐标不混淆
                    boolean reTimeFlag = false;// 用于区分坐标不混淆
                    boolean amountFlag = false;// 用于区分坐标不混淆
                    boolean sRemarkFlag = false;// 用于区分坐标不混淆
                    boolean oFlag = false;// 订单存在标识
                    //行
                    for (int i = 0; i < listInfo.size() - 1; i++) {
                        //所有列
                        List<Object> objList = listInfo.get(i);
                        //不含标题头所有列
                        List<Object> objListValue = new ArrayList<Object>();
                        if (i <= (listInfo.size() - 2)) {
                            objListValue = listInfo.get((i + 1));
                        }
                        // EXCEL标题头
                        if (i == 0) {
                            errorList.add(listInfo.get(0));
                        }
                        XeVenFinSalesBillForm paraFinSalesBillForm = new XeVenFinSalesBillForm();
                        paraFinSalesBillForm.setUserCode(userInfo.getUserCode());
                        paraFinSalesBillForm.setSbillCode(objListValue.get(1).toString());
                        List<XeVenFinSalesBillExDTO> finSalesBillEList = finPurchPayCenterExportService.queryExportfinSalesBillList(paraFinSalesBillForm);
                        // 需要更新的收款单实体
                        XeVenFinSalesBillForm finSalesBillForm = new XeVenFinSalesBillForm();
                        for (int j = 0; j < objList.size(); j++) {

                            // -----------验证订单-------
                            if ("订单编号".equals(objList.get(j).toString().trim())) {
                                orderIndexs = j;
                                orderFlag = true;
                            }
                            // 判断是否是订单数据
                            if (objListValue.size() > 0 && orderFlag) {
                                // 取出EXCEL中订单编号，并判断数据库中是否存在
                                if (dbOrders.contains(objListValue.get(orderIndexs))) {
                                    // 如果订单存在
                                    oFlag = true;
                                } else {
                                    // 如果有不存在的订单返回错误数据
                                    errorList.add(objListValue);
                                }
                            }

                            // --------收款方式-----------
                            if (objList.get(j).toString().trim().equals("收款方式")) {
                                payIndexs = j;
                                payFlag = true;
                            }
                            // 判断是否是收款方式数据
                            if (payFlag && objListValue.size() > 0) {
                                // 取出EXCEL中收款方式
                                if (!StringUtils.isEmpty(objListValue.get(payIndexs)) && org.apache.commons.lang.StringUtils.isNumeric(new Double(objListValue.get(payIndexs).toString()).intValue() + "")) {
                                    // 如果不为空设置需要更新的数据
                                    finSalesBillForm.setSbillPayType(new Double(objListValue.get(payIndexs).toString()).intValue());
                                } else {
                                    // 为空默认pos支付
                                    finSalesBillForm.setSbillPayType(1);
                                }
                            }
                            // --------收款日期-----------
                            if (objList.get(j).toString().trim().equals("收款日期")) {
                                reTimeIndexs = j;
                                reTimeFlag = true;
                            }
                            // 判断是否是收款日期数据
                            if (objListValue.size() > 0 && reTimeFlag) {
                                // 取出EXCEL中收款日期
                                if (!StringUtils.isEmpty(objListValue.get(reTimeIndexs))) {
                                    // 如果不为空设置需要更新的数据
                                    finSalesBillForm.setReceiveTime(DateUtil.toDate(objListValue.get(reTimeIndexs) + ""));
                                }
                            }
                            // --------实收金额-----------
                            if (objList.get(j).toString().trim().equals("实收金额")) {
                                amountIndexs = j;
                                amountFlag = true;
                            }
                            // 判断是否是实收金额数据
                            if (objListValue.size() > 0 && amountFlag) {
                                // 取出EXCEL中实收金额
                                if (!StringUtils.isEmpty(objListValue.get(amountIndexs))) {
                                    // 如果不为空设置需要更新的数据
                                    finSalesBillForm.setRealSbillAmount(new BigDecimal(objListValue.get(amountIndexs) + ""));
                                } else {
                                    //默认等于实收金额
                                    finSalesBillForm.setRealSbillAmount(finSalesBillEList.get(0).getSfAmount());
                                }
                            }
                            // --------收款单备注-----------
                            if (objList.get(j).toString().trim().equals("备注")) {
                                sRemarkIndexs = j;
                                sRemarkFlag = true;
                            }
                            // 判断是否是收款单备注数据
                            if (objListValue.size() > 0 && sRemarkFlag) {
                                // 取出EXCEL中收款单备注
                                if (!StringUtils.isEmpty(objListValue.get(sRemarkIndexs))) {
                                    // 如果不为空设置需要更新的数据
                                    finSalesBillForm.setSbillRemark(objListValue.get(sRemarkIndexs) + "");
                                }
                            }
                            finSalesBillForm.setSbillCode(objListValue.get(1) + "");
                        }
                        //当前应收等于实收更新为已收款，实收小于应收更新为部分收款
                        if (new BigDecimal(finSalesBillForm.getRealSbillAmount().toString()).compareTo(new BigDecimal(finSalesBillEList.get(0).getSfAmount() + "")) < 0) {
                            finSalesBillForm.setSbillStatus(2);
                        } else if (new BigDecimal(finSalesBillEList.get(0).getSfAmount() + "").compareTo(new BigDecimal(finSalesBillForm.getRealSbillAmount().toString())) == 0) {
                            finSalesBillForm.setSbillStatus(3);
                        } else {
                            finSalesBillForm.setSbillStatus(1);
                        }
                        yesList.add(finSalesBillForm);
                    }
                    // 更新验证成功的数据
                    for (XeVenFinSalesBillForm form : yesList) {
                        log.info("form-------->>" + JSON.toJSONString(form));
                        xeVenFinSalesBillService.updateXeVenFinSalesBill(form);
                    }
                    if (errorList.size() > 1) {
                        rsInfoMap.put("info", "导入失败" + errorList.size() + "条，订单编号不存在请核查");
                        // 生成未成功的excel数据
                        log.info("errorList-------->>" + errorList);
                        XeVenExcelUtil excelUtil = new XeVenExcelUtil(exportTempletDir);
                        String salesBillErrorUrl = excelUtil.createExcelByLists(errorList,
                                "SALESBILLERROR" + XeVenExcelUtil.getCurDateStrTemName() + ".xls");
                        rsInfoMap.put("downErrorInfoUrl", salesBillErrorUrl);
                    }
                    return sendAjaxOK(rsInfoMap);
                } else {
                    return sendAjaxError("请选择正确的文件！");
                }
            } else {
                return sendAjaxError("请选择导入正确的文件！");
            }
        } catch (Exception e) {
            log.error("收款单列表导入接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 点击确定下载EXCEL错误信息
     *
     * @author 赵盼飞
     */
    @RequestMapping("exportImErrorExcel")
    public @ResponseBody
    BaseResponse exportImErrorExcel(@ModelAttribute XeVenFinSalesBillForm form,
                                    HttpServletResponse response) {

        try {
            XeVenExcelUtil.download(form.getDownErrorInfoUrl(), response);
            return sendAjaxOK();
        } catch (Exception e) {
            log.error("点击确定下载EXCEL错误信息接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 退款单导出列表
     *
     * @author 赵盼飞
     */
    @RequestMapping("exRefundOrderList")
    public @ResponseBody
    BaseResponse exRefundOrderList(@ModelAttribute XeVenOrderRefundQueryForm form,
                                   HttpServletResponse response) {
        try {
            String[] str = new String[]{"refundCode", "createDate", "refundType", "refundStatus", "afterSalesCode",
                    "rejectCode", "orderId", "loginAccount", "payType", "payChannel", "refundDate",
                    "realRefundedAmount"};
            form.setFieldArr(str);

            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            if (org.apache.commons.lang.StringUtils.isNotBlank(form.getFormIdType())) {
                //1=退款单号  2=售后单号 3=订单编号  4=商品名称 5=商品货号  6=客户账号 7=退货单号
                int formIdType = Integer.parseInt(form.getFormIdType());
                switch (formIdType) {
                    case 1:   //退款单号
                        form.setRefundCode(form.getFormIdValue());
                        break;
                    case 2:   //售后单号
                        form.setAfterSalesCode(form.getFormIdValue());
                        break;
                    case 3:   //订单信息
                        form.setOrderId(form.getFormIdValue());
                        break;
                    case 4:   //商品名称
                        form.setProName(form.getFormIdValue());
                        break;
                    case 5:   //商品货号
                        form.setProNum(form.getFormIdValue());
                        break;
                    case 6:   //客户账号
                        form.setLoginAccount(form.getFormIdValue());
                        break;
                    case 7:   //退货单号
                        form.setRejectCode(form.getFormIdValue());
                        break;
                    default:
                        break;
                }
            }


            String startTime = form.getFormStartTime();
            String endTime = form.getFormEndTime();
            //设定查询中日期为3个月以内
            if (org.apache.commons.lang.StringUtils.isNotBlank(startTime) && org.apache.commons.lang.StringUtils.isNotBlank(endTime)) {
                Boolean dateCm = DateUtil.comparableTime(startTime, endTime);
                if (!dateCm) {
                    return sendAjaxError(XeVenAfterSaleMsg.AFTER_SALE_DATE_COMPARABLE);
                }
            }
            if (org.apache.commons.lang.StringUtils.isBlank(startTime) && org.apache.commons.lang.StringUtils.isBlank(endTime)) {
                endTime = DateUtil.getDate(new Date());
                ;
                startTime = DateUtil.strToNMonth(endTime, -3);
            }
            if (org.apache.commons.lang.StringUtils.isBlank(startTime) && org.apache.commons.lang.StringUtils.isNotBlank(endTime)) {
                startTime = DateUtil.strToNMonth(endTime, -3);
            }
            if (org.apache.commons.lang.StringUtils.isBlank(endTime) && org.apache.commons.lang.StringUtils.isNotBlank(startTime)) {
                endTime = DateUtil.strToNMonth(startTime, 3);
            }
            int formTimeType = form.getFormTimeType();
            //1=创建时间 2=退款时间
            switch (formTimeType) {
                case 1:
                    form.setCreateStartTime(startTime);
                    form.setCreateEndTime(endTime);
                    break;
                case 2:
                    form.setRefundStartTime(startTime);
                    form.setRefundEndTime(endTime);
                default:
                    break;
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());

            // 2.获取数据
            List<XeVenOrderRefundDTO> refundOrderList = finPurchPayCenterExportService.exRefundOrderList(form);
            if (null != refundOrderList && refundOrderList.size() > 0) {
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(refundOrderList, new XeVenOrderRefundDTO(),
                        form.getFieldArr(), exportTempletDir, "REFUNDORDERLIST-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("退款单列表导出接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 退款单导出明细
     *
     * @author 赵盼飞
     */
    @RequestMapping("exRefundOrderDetail")
    public @ResponseBody
    BaseResponse exRefundOrderDetail(@ModelAttribute XeVenOrderRefundQueryForm form,
                                     HttpServletResponse response) {
        try {
            String[] str = new String[]{"refundCode", "createDate", "refundType", "refundStatus", "afterSalesCode",
                    "rejectCode", "orderId", "loginAccount", "payType", "payChannel", "refundDate",
                    "realRefundedAmount", "proNum", "proName", "proOrgCodeName", "pricingType", "proUnit", "specValue",
                    "proCostPrice", "purchaseNum", "proTotalPrice", "pmtAmount", "specialDisamount", "realSendNum",
                    "rejectAmount", "rejectNums", "refundAmount"};
            form.setFieldArr(str);

            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            if (org.apache.commons.lang.StringUtils.isNotBlank(form.getFormIdType())) {
                //1=退款单号  2=售后单号 3=订单编号  4=商品名称 5=商品货号  6=客户账号 7=退货单号
                int formIdType = Integer.parseInt(form.getFormIdType());
                switch (formIdType) {
                    case 1:   //退款单号
                        form.setRefundCode(form.getFormIdValue());
                        break;
                    case 2:   //售后单号
                        form.setAfterSalesCode(form.getFormIdValue());
                        break;
                    case 3:   //订单信息
                        form.setOrderId(form.getFormIdValue());
                        break;
                    case 4:   //商品名称
                        form.setProName(form.getFormIdValue());
                        break;
                    case 5:   //商品货号
                        form.setProNum(form.getFormIdValue());
                        break;
                    case 6:   //客户账号
                        form.setLoginAccount(form.getFormIdValue());
                        break;
                    case 7:   //退货单号
                        form.setRejectCode(form.getFormIdValue());
                        break;
                    default:
                        break;
                }
            }


            String startTime = form.getFormStartTime();
            String endTime = form.getFormEndTime();
            //设定查询中日期为3个月以内
            if (org.apache.commons.lang.StringUtils.isNotBlank(startTime) && org.apache.commons.lang.StringUtils.isNotBlank(endTime)) {
                Boolean dateCm = DateUtil.comparableTime(startTime, endTime);
                if (!dateCm) {
                    return sendAjaxError(XeVenAfterSaleMsg.AFTER_SALE_DATE_COMPARABLE);
                }
            }
            if (org.apache.commons.lang.StringUtils.isBlank(startTime) && org.apache.commons.lang.StringUtils.isBlank(endTime)) {
                endTime = DateUtil.getDate(new Date());
                ;
                startTime = DateUtil.strToNMonth(endTime, -3);
            }
            if (org.apache.commons.lang.StringUtils.isBlank(startTime) && org.apache.commons.lang.StringUtils.isNotBlank(endTime)) {
                startTime = DateUtil.strToNMonth(endTime, -3);
            }
            if (org.apache.commons.lang.StringUtils.isBlank(endTime) && org.apache.commons.lang.StringUtils.isNotBlank(startTime)) {
                endTime = DateUtil.strToNMonth(startTime, 3);
            }
            int formTimeType = form.getFormTimeType();
            //1=创建时间 2=退款时间
            switch (formTimeType) {
                case 1:
                    form.setCreateStartTime(startTime);
                    form.setCreateEndTime(endTime);
                    break;
                case 2:
                    form.setRefundStartTime(startTime);
                    form.setRefundEndTime(endTime);
                default:
                    break;
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            // 2.获取数据
            List<XeVenOrderRefundDTO> refundOrderList = finPurchPayCenterExportService.exRefundOrderDetail(form);
            if (null != refundOrderList && refundOrderList.size() > 0) {
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(refundOrderList, new XeVenOrderRefundDTO(),
                        form.getFieldArr(), exportTempletDir, "REFUNDORDERDETAIL-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("退款单导出明细接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 我的应付账单列表导出
     *
     * @author 赵盼飞
     */
    @RequestMapping("queryMineFinPurchPayExportList")
    public @ResponseBody
    BaseResponse queryMineFinPurchPayExportList(@ModelAttribute XeSysFinPayBillRequestDTO form,
                                                HttpServletResponse response) {

        try {
            // 测试
            String[] str = new String[]{"reviewStatus", "pbMonth", "pbCode", "createDate", "remark", "pbStatus",
                    "payAmount", "actPayAmount", "profitAmount", "unPayAmount", "preAmount", "expenseType", "purchSettleWay",
                    "settleDate", "accBank", "bankAccName", "bankAccCard"};
            form.setFieldArr(str);
            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            form.setPbType(1);
            form.setReviewStatus(1);
            form.setConfirmBill(2);
            form.setCancelStatus(1);
            // 2.掉二方包获取数据
            ManagerFinPayBillPageDto rsDto = xeSysFinPayBillRestApiService.listSysFinBkgExportExcel(form);
            if (null != rsDto && rsDto.getList().size() > 0) {
                List<XeSysFinPayBillExport> dataList = new ArrayList<XeSysFinPayBillExport>();
                for (int i = 0; i < rsDto.getList().size(); i++) {
                    XeSysFinPayBillExport en = new XeSysFinPayBillExport();
                    if (rsDto.getList().get(i).getReviewStatus() == 1) {
                        en.setReviewStatus("未复核");
                    } else if (rsDto.getList().get(i).getReviewStatus() == 2) {
                        en.setReviewStatus("已复核");
                    } else if (rsDto.getList().get(i).getReviewStatus() == 3) {
                        en.setReviewStatus("复核异常");
                    }
                    en.setPbMonth(rsDto.getList().get(i).getPbMonth() + "月份");
                    en.setPbCode(rsDto.getList().get(i).getPbCode());
                    en.setCreateDate(DateUtil.getDate(rsDto.getList().get(i).getCreateDate()));
                    en.setRemark(rsDto.getList().get(i).getRemark());
                    if (rsDto.getList().get(i).getPbStatus() == 1) {
                        en.setPbStatus("未结账");
                    } else if (rsDto.getList().get(i).getPbStatus() == 2) {
                        en.setPbStatus("部分结账");
                    } else if (rsDto.getList().get(i).getPbStatus() == 3) {
                        en.setPbStatus("已结账");
                    }
                    en.setPayAmount(rsDto.getList().get(i).getPayAmount());
                    en.setActPayAmount(rsDto.getList().get(i).getActPayAmount());
                    en.setProfitAmount(rsDto.getList().get(i).getProfitAmount());
                    en.setUnPayAmount(rsDto.getList().get(i).getUnPayAmount());
                    if (rsDto.getList().get(i).getExpenseType() == 1) {
                        en.setExpenseType("采购付款");
                    } else if (rsDto.getList().get(i).getExpenseType() == 2) {
                        en.setExpenseType("其它");
                    }
                    if (rsDto.getList().get(i).getPurchSettleWay() == 1) {
                        en.setPurchSettleWay("账期结算");
                    } else if (rsDto.getList().get(i).getPurchSettleWay() == 2) {
                        en.setPurchSettleWay("预付款");
                    } else if (rsDto.getList().get(i).getPurchSettleWay() == 3) {
                        en.setPurchSettleWay("现结");
                    }
                    if (null != rsDto.getList().get(i).getSettleDate()) {
                        en.setSettleDate(DateUtil.getDate(rsDto.getList().get(i).getSettleDate()));
                    }
                    en.setAccBank(rsDto.getList().get(i).getAccBank());
                    en.setBankAccCard(rsDto.getList().get(i).getBankAccCard());
                    en.setBankAccName(rsDto.getList().get(i).getBankAccName());
                    en.setPreAmount(rsDto.getList().get(i).getPreAmount());
                    dataList.add(en);
                }
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(dataList, new XeSysFinPayBillExport(),
                        form.getFieldArr(), exportTempletDir, "MINEFINPURCHPAYLIST-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("我的应付账单列表导出接口异常：{}", e);
            return sendAjaxError();
        }

    }

    /**
     * 平台应付账单列表导出
     *
     * @author 赵盼飞
     */
    @RequestMapping("queryPlatformFinPurchPayExportList")
    public @ResponseBody
    BaseResponse queryPlatformFinPurchPayExportList(@ModelAttribute XeSysFinPayBillRequestDTO form,
                                                    HttpServletResponse response) {

        try {
            // 测试
            String[] str = new String[]{"reviewStatus", "pbMonth", "pbCode", "createDate", "pbStatus",
                    "payAmount", "actPayAmount", "profitAmount", "unPayAmount", "expenseType", "purchSettleWay",
                    "settleDate", "cutPayAmountTotal", "rbCode", "refundAmountTotal"};
            form.setFieldArr(str);
            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            form.setPbType(2);
            form.setReviewStatus(1);
            form.setConfirmBill(2);
            form.setCancelStatus(1);
            // 2.掉二方包获取数据
            ManagerFinPayBillPageDto rsDto = xeSysFinPayBillRestApiService.listSysFinBkgExportExcel(form);
            if (null != rsDto && rsDto.getList().size() > 0) {
                List<XeSysFinPayBillExport> dataList = new ArrayList<XeSysFinPayBillExport>();
                for (int i = 0; i < rsDto.getList().size(); i++) {
                    XeSysFinPayBillExport en = new XeSysFinPayBillExport();
                    if (rsDto.getList().get(i).getReviewStatus() == 1) {
                        en.setReviewStatus("未复核");
                    } else if (rsDto.getList().get(i).getReviewStatus() == 2) {
                        en.setReviewStatus("已复核");
                    } else if (rsDto.getList().get(i).getReviewStatus() == 3) {
                        en.setReviewStatus("复核异常");
                    }
                    en.setPbMonth(rsDto.getList().get(i).getPbMonth() + "月份");
                    en.setPbCode(rsDto.getList().get(i).getPbCode());
                    en.setCreateDate(DateUtil.getDate(rsDto.getList().get(i).getCreateDate()));
//					en.setRemark(rsDto.getList().get(i).getRemark());
                    if (rsDto.getList().get(i).getPbStatus() == 1) {
                        en.setPbStatus("未结账");
                    } else if (rsDto.getList().get(i).getPbStatus() == 2) {
                        en.setPbStatus("部分结账");
                    } else if (rsDto.getList().get(i).getPbStatus() == 3) {
                        en.setPbStatus("已结账");
                    }
                    en.setPayAmount(rsDto.getList().get(i).getPayAmount());
                    en.setActPayAmount(rsDto.getList().get(i).getActPayAmount());
                    en.setProfitAmount(rsDto.getList().get(i).getProfitAmount());
                    en.setUnPayAmount(rsDto.getList().get(i).getUnPayAmount());
                    if (rsDto.getList().get(i).getExpenseType() == 1) {
                        en.setExpenseType("采购付款");
                    } else if (rsDto.getList().get(i).getExpenseType() == 2) {
                        en.setExpenseType("其它");
                    }
                    if (rsDto.getList().get(i).getBkgeSettleWay() == 1) {
                        en.setPurchSettleWay("按固定周期");
                    } else if (rsDto.getList().get(i).getBkgeSettleWay() == 2) {
                        en.setPurchSettleWay("按固定日");
                    }
                    if (null != rsDto.getList().get(i).getSettleDate()) {
                        en.setSettleDate(DateUtil.getDate(rsDto.getList().get(i).getSettleDate()));
                    }
                    if (null != rsDto.getList().get(i).getRefundAmountTotal()) {
                        en.setRefundAmountTotal(rsDto.getList().get(i).getRefundAmountTotal());
                    }
                    if (null != rsDto.getList().get(i).getCutPayAmountTotal()) {
                        en.setCutPayAmountTotal(rsDto.getList().get(i).getCutPayAmountTotal());
                    }
                    if (null != rsDto.getList().get(i).getRbCode()) {
                        en.setRbCode(rsDto.getList().get(i).getRbCode());
                    }
                    dataList.add(en);
                }
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(dataList, new XeSysFinPayBillExport(),
                        form.getFieldArr(), exportTempletDir, "PLATFORMFINPURCHPAYLIST-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("平台应付账单列表导出接口异常：{}", e);
            return sendAjaxError();
        }

    }


    /**
     * 我的应付账单列表导出明细
     *
     * @author 赵盼飞
     */
    @RequestMapping("queryMineFinPurchPayExportDetail")
    public @ResponseBody
    BaseResponse queryMineFinPurchPayExportDetail(@ModelAttribute XeSysFinPayBillRequestDTO form,
                                                  HttpServletResponse response) {

        try {
            // 测试
            String[] str = new String[]{"reviewStatus", "pbMonth", "pbCode", "createDate", "remark", "pbStatus",
                    "payAmount", "actPayAmount", "profitAmount", "unPayAmount", "expenseType", "purchSettleWay",
                    "settleDate", "orderId", "sendTime", "proName", "specValue", "proNum", "pricingType",
                    "proCostPrice", "purchaseNum", "proUnit", "proTotalPrice", "realSendNum", "proPayAmount",
                    "profitAmountDetail", "purchPrice", "realPayAmount", "cutPayAmount", "cutReason", "purchAdress",
                    "purchPayStatus", "accBank", "bankAccName", "bankAccCard"};
            form.setFieldArr(str);
            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            form.setPbType(1);
            form.setReviewStatus(1);
            form.setConfirmBill(2);
            form.setCancelStatus(1);
            // 2.掉二方包获取数据
            ManagerFinPayBillPageDto rsDto = xeSysFinPayBillRestApiService.listSysFinBkgExportDetailExcel(form);
            if (null != rsDto && rsDto.getList().size() > 0) {
                List<XeSysFinPayBillExport> dataList = new ArrayList<XeSysFinPayBillExport>();
                for (int i = 0; i < rsDto.getList().size(); i++) {
                    XeSysFinPayBillExport en = new XeSysFinPayBillExport();
                    if (rsDto.getList().get(i).getReviewStatus() == 1) {
                        en.setReviewStatus("未复核");
                    } else if (rsDto.getList().get(i).getReviewStatus() == 2) {
                        en.setReviewStatus("已复核");
                    } else if (rsDto.getList().get(i).getReviewStatus() == 3) {
                        en.setReviewStatus("复核异常");
                    }
                    en.setPbMonth(rsDto.getList().get(i).getPbMonth() + "月份");
                    en.setPbCode(rsDto.getList().get(i).getPbCode());
                    en.setCreateDate(DateUtil.getDate(rsDto.getList().get(i).getCreateDate()));
                    en.setRemark(rsDto.getList().get(i).getRemark());
                    if (rsDto.getList().get(i).getPbStatus() == 1) {
                        en.setPbStatus("未结账");
                    } else if (rsDto.getList().get(i).getPbStatus() == 2) {
                        en.setPbStatus("部分结账");
                    } else if (rsDto.getList().get(i).getPbStatus() == 3) {
                        en.setPbStatus("已结账");
                    }
                    en.setPayAmount(rsDto.getList().get(i).getPayAmount());
                    en.setActPayAmount(rsDto.getList().get(i).getActPayAmount());
                    en.setProfitAmount(rsDto.getList().get(i).getProfitAmount());
                    en.setUnPayAmount(rsDto.getList().get(i).getUnPayAmount());
                    if (rsDto.getList().get(i).getExpenseType() == 1) {
                        en.setExpenseType("采购付款");
                    } else if (rsDto.getList().get(i).getExpenseType() == 2) {
                        en.setExpenseType("其它");
                    }
                    if (rsDto.getList().get(i).getPurchSettleWay() == 1) {
                        en.setPurchSettleWay("账期结算");
                    } else if (rsDto.getList().get(i).getPurchSettleWay() == 2) {
                        en.setPurchSettleWay("预付款");
                    } else if (rsDto.getList().get(i).getPurchSettleWay() == 3) {
                        en.setPurchSettleWay("现结");
                    }
                    if (null != rsDto.getList().get(i).getSettleDate()) {
                        en.setSettleDate(DateUtil.getDate(rsDto.getList().get(i).getSettleDate()));
                    }
                    en.setOrderId(rsDto.getList().get(i).getOrderId());
                    if (null != rsDto.getList().get(i).getSendTime()) {
                        en.setSendTime(DateUtil.getDate(rsDto.getList().get(i).getSendTime()));
                    }
                    en.setProName(rsDto.getList().get(i).getProName());
                    en.setSpecValue(rsDto.getList().get(i).getSpecValue());
                    en.setProNum(rsDto.getList().get(i).getProNum());

                    if (rsDto.getList().get(i).getPricingType().toString().equals("1")) {
                        en.setPricingType("重量");
                    } else if (rsDto.getList().get(i).getPricingType().toString().equals("2")) {
                        en.setPricingType("数量");
                    }
                    en.setProCostPrice(rsDto.getList().get(i).getProCostPrice());
                    en.setPurchaseNum(rsDto.getList().get(i).getPurchaseNum());
                    en.setProUnit(rsDto.getList().get(i).getProUnit());
                    en.setProTotalPrice(rsDto.getList().get(i).getProTotalPrice());
                    en.setRealSendNum(rsDto.getList().get(i).getRealSendNum());
                    en.setProPayAmount(rsDto.getList().get(i).getProPayAmount());
                    en.setProfitAmountDetail(rsDto.getList().get(i).getProfitAmountDetail());
                    en.setPurchPrice(rsDto.getList().get(i).getPurchPrice());
                    en.setRealPayAmount(rsDto.getList().get(i).getRealPayAmount());
                    en.setCutPayAmount(rsDto.getList().get(i).getCutPayAmount());
                    en.setCutReason(rsDto.getList().get(i).getCutReason());
                    en.setPurchAdress(rsDto.getList().get(i).getPurchAdress());
                    if (rsDto.getList().get(i).getPurchPayStatus() == 1) {
                        en.setPurchPayStatus("未结算");
                    } else if (rsDto.getList().get(i).getPurchPayStatus() == 2) {
                        en.setPurchPayStatus("结算中");
                    } else if (rsDto.getList().get(i).getPurchPayStatus() == 3) {
                        en.setPurchPayStatus("已结算");
                    }
                    en.setAccBank(rsDto.getList().get(i).getAccBank());
                    en.setBankAccCard(rsDto.getList().get(i).getBankAccCard());
                    en.setBankAccName(rsDto.getList().get(i).getBankAccName());
                    dataList.add(en);
                }
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(dataList, new XeSysFinPayBillExport(),
                        form.getFieldArr(), exportTempletDir, "MINEFINPURCHPAYDETAIL-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("我的应付账单列表导出明细接口异常：{}", e);
            return sendAjaxError();
        }

    }


    /**
     * 平台应付账单列表导出明细
     *
     * @author 赵盼飞
     */
    @RequestMapping("queryPlatformFinPurchPayExportDetail")
    public @ResponseBody
    BaseResponse queryPlatformFinPurchPayExportDetail(@ModelAttribute XeSysFinPayBillRequestDTO form,
                                                      HttpServletResponse response) {

        try {
            // 测试
            String[] str = new String[]{"reviewStatus", "pbMonth", "pbCode", "createDate", "remark", "pbStatus",
                    "payAmount", "actPayAmount", "profitAmount", "unPayAmount", "expenseType", "purchSettleWay",
                    "settleDate", "orderId", "sendTime", "proName", "specValue", "proNum", "pricingType",
                    "proCostPrice", "purchaseNum", "proUnit", "proTotalPrice", "realSendNum", "proPayAmount",
                    "bkgeRate", "bkgeAmountDetail", "purchPrice", "realPayAmount", "cutPayAmount", "cutReason", "purchAdress",
                    "purchPayStatus"};
            form.setFieldArr(str);
            // 1、验证参数
            if (form.getFieldArr().length <= 0) {
                return sendAjaxError(BASEMessage.PARAM_ERROR);
            }
            ErpUserInfo userInfo = SysSetBeanUtils.getErpUserInfo(super.getErpLoginUserInfo());
            form.setUserCode(userInfo.getUserCode());
            form.setPbType(2);
            form.setReviewStatus(1);
            form.setConfirmBill(2);
            form.setCancelStatus(1);
            // 2.掉二方包获取数据
            ManagerFinPayBillPageDto rsDto = xeSysFinPayBillRestApiService.listSysFinBkgExportDetailExcel(form);
            if (null != rsDto && rsDto.getList().size() > 0) {
                List<XeSysFinPayBillExport> dataList = new ArrayList<XeSysFinPayBillExport>();
                for (int i = 0; i < rsDto.getList().size(); i++) {
                    XeSysFinPayBillExport en = new XeSysFinPayBillExport();
                    if (rsDto.getList().get(i).getReviewStatus() == 1) {
                        en.setReviewStatus("未复核");
                    } else if (rsDto.getList().get(i).getReviewStatus() == 2) {
                        en.setReviewStatus("已复核");
                    } else if (rsDto.getList().get(i).getReviewStatus() == 3) {
                        en.setReviewStatus("复核异常");
                    }
                    en.setPbMonth(rsDto.getList().get(i).getPbMonth() + "月份");
                    en.setPbCode(rsDto.getList().get(i).getPbCode());
                    en.setCreateDate(DateUtil.getDate(rsDto.getList().get(i).getCreateDate()));
                    en.setRemark(rsDto.getList().get(i).getRemark());
                    if (rsDto.getList().get(i).getPbStatus() == 1) {
                        en.setPbStatus("未结账");
                    } else if (rsDto.getList().get(i).getPbStatus() == 2) {
                        en.setPbStatus("部分结账");
                    } else if (rsDto.getList().get(i).getPbStatus() == 3) {
                        en.setPbStatus("已结账");
                    }
                    en.setPayAmount(rsDto.getList().get(i).getPayAmount());
                    en.setActPayAmount(rsDto.getList().get(i).getActPayAmount());
                    en.setProfitAmount(rsDto.getList().get(i).getProfitAmount());
                    en.setUnPayAmount(rsDto.getList().get(i).getUnPayAmount());
                    if (rsDto.getList().get(i).getExpenseType() == 1) {
                        en.setExpenseType("采购付款");
                    } else if (rsDto.getList().get(i).getExpenseType() == 2) {
                        en.setExpenseType("其它");
                    }
                    if (rsDto.getList().get(i).getBkgeSettleWay() == 1) {
                        en.setPurchSettleWay("按固定周期");
                    } else if (rsDto.getList().get(i).getBkgeSettleWay() == 2) {
                        en.setPurchSettleWay("按固定日");
                    }
                    if (null != rsDto.getList().get(i).getSettleDate()) {
                        en.setSettleDate(DateUtil.getDate(rsDto.getList().get(i).getSettleDate()));
                    }
                    en.setOrderId(rsDto.getList().get(i).getOrderId());
                    if (!StringUtils.isEmpty(rsDto.getList().get(i).getSendTime())) {
                        en.setSendTime(DateUtil.getDate(rsDto.getList().get(i).getSendTime()));
                    }
                    en.setProName(rsDto.getList().get(i).getProName());
                    en.setSpecValue(rsDto.getList().get(i).getSpecValue());
                    en.setProNum(rsDto.getList().get(i).getProNum());

                    if (rsDto.getList().get(i).getPricingType().toString().equals("1")) {
                        en.setPricingType("重量");
                    } else if (rsDto.getList().get(i).getPricingType().toString().equals("2")) {
                        en.setPricingType("数量");
                    }
                    en.setProCostPrice(rsDto.getList().get(i).getProCostPrice());
                    en.setPurchaseNum(rsDto.getList().get(i).getPurchaseNum());
                    en.setProUnit(rsDto.getList().get(i).getProUnit());
                    en.setProTotalPrice(rsDto.getList().get(i).getProTotalPrice());
                    en.setRealSendNum(rsDto.getList().get(i).getRealSendNum());
                    en.setProPayAmount(rsDto.getList().get(i).getProPayAmount());
                    en.setBkgeRate(rsDto.getList().get(i).getBkgeRate());
                    en.setBkgeAmountDetail(rsDto.getList().get(i).getBkgeAmountDetail());
                    en.setPurchPrice(rsDto.getList().get(i).getPurchPrice());
                    en.setRealPayAmount(rsDto.getList().get(i).getRealPayAmount());
                    en.setCutPayAmount(rsDto.getList().get(i).getCutPayAmount());
                    en.setCutReason(rsDto.getList().get(i).getCutReason());
                    en.setPurchAdress(rsDto.getList().get(i).getPurchAdress());
                    if (rsDto.getList().get(i).getPurchPayStatus() == 1) {
                        en.setPurchPayStatus("未结算");
                    } else if (rsDto.getList().get(i).getPurchPayStatus() == 2) {
                        en.setPurchPayStatus("结算中");
                    } else if (rsDto.getList().get(i).getPurchPayStatus() == 3) {
                        en.setPurchPayStatus("已结算");
                    }
                    dataList.add(en);
                }
                // 3.导出
                boolean rs = XeVenExcelUtil.exportExcelService(dataList, new XeSysFinPayBillExport(),
                        form.getFieldArr(), exportTempletDir, "PLATFORMFINPURCHPAYDETAIL-", response);
                if (rs) {
                    return sendAjaxOK();
                } else {
                    return sendAjaxError();
                }
            } else {
                return sendAjaxOK("导出数据为空！");
            }
        } catch (Exception e) {
            log.error("平台应付账单列表导出明细接口异常：{}", e);
            return sendAjaxError();
        }
    }
}
